package com.fr.chart.core.glyph;

import com.fr.base.core.IteratorChain;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GeneralInfo;
import com.fr.chart.axis.DataLabelInfo;
import com.fr.chart.axis.SeriesAttrPosition;
import com.fr.chart.axis.SeriesAttrTrendLine;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.RectangleGlyph;
import com.fr.chart.core.TrendLine;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.chart.plot.SeriesCollection;
import com.fr.report.js.NameJavaScriptGroup;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class PlotGlyph extends RectangleGlyph
{
  private static final long serialVersionUID = -2464599809725765353L;
  public static final String XML_TAG = "PlotGlyph";
  protected List seriesList = new ArrayList();
  private SeriesCollection seriesCollection = new SeriesCollection();
  private NameJavaScriptGroup hotHyperLink;
  private String hotTooltip = null;
  private boolean isNullValueBreak;

  public void addSeries(DataSeries paramDataSeries)
  {
    this.seriesList.add(paramDataSeries);
  }

  public int getSeriesSize()
  {
    return this.seriesList.size();
  }

  public DataSeries getSeries(int paramInt)
  {
    if (paramInt < this.seriesList.size())
      return ((DataSeries)this.seriesList.get(paramInt));
    return null;
  }

  public int getCategoryCount()
  {
    if (getSeries(0) != null)
      return getSeries(0).getDataPointCount();
    return 0;
  }

  public Iterator selectableChildren()
  {
    return new IteratorChain(new Iterator[] { this.seriesList.iterator() });
  }

  public boolean supportJSDrawing()
  {
    return true;
  }

  public void draw(Graphics paramGraphics)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    localGraphics2D.translate(getBounds().getX(), getBounds().getY());
    int i = 0;
    int j = getSeriesSize();
    while (i < j)
    {
      getSeries(i).draw(paramGraphics);
      ++i;
    }
    i = 0;
    j = getSeriesSize();
    while (i < j)
    {
      getSeries(i).drawLabel(paramGraphics);
      ++i;
    }
    i = 0;
    j = getSeriesSize();
    while (i < j)
    {
      getSeries(i).drawTrendLine(paramGraphics);
      ++i;
    }
    localGraphics2D.translate(-getBounds().getX(), -getBounds().getY());
  }

  public void drawInfo(Graphics paramGraphics)
  {
    getInfo().paint(paramGraphics, getOutline4Fill());
  }

  public abstract void layoutAxisGlyph();

  public abstract void layoutDataSeriesGlyph();

  protected void dealDataPointLabelBounds(DataPoint paramDataPoint, int paramInt)
  {
    TextGlyph localTextGlyph1 = paramDataPoint.getDataLabel();
    if (localTextGlyph1 instanceof TextGlyph)
    {
      TextGlyph localTextGlyph2 = (TextGlyph)localTextGlyph1;
      SeriesAttrPosition localSeriesAttrPosition = (SeriesAttrPosition)getSeriesCollection().getSeriesCondition(new SeriesAttrPosition(), paramInt);
      Rectangle2D localRectangle2D = DataLabelInfo.preferredLabelBounds(localTextGlyph2, paramDataPoint, localSeriesAttrPosition.getPosition());
      localTextGlyph2.setBounds(localRectangle2D);
    }
  }

  public void axisExtends(AxisGlyph paramAxisGlyph)
  {
    int i = 0;
    int j = 0;
    int k = 0;
    int l = getSeriesSize();
    while (k < l)
    {
      SeriesAttrTrendLine localSeriesAttrTrendLine = (SeriesAttrTrendLine)getSeriesCollection().getSeriesCondition(new SeriesAttrTrendLine(), k);
      if (localSeriesAttrTrendLine != null)
      {
        if (localSeriesAttrTrendLine.getBackward() > i)
          i = localSeriesAttrTrendLine.getBackward();
        if (localSeriesAttrTrendLine.getForward() > j)
          j = localSeriesAttrTrendLine.getForward();
      }
      ++k;
    }
    paramAxisGlyph.axisExtends(j, i);
  }

  protected void trendLineFitting(double[] paramArrayOfDouble1, double[] paramArrayOfDouble2, int paramInt)
  {
    DataSeries localDataSeries = getSeries(paramInt);
    SeriesAttrTrendLine localSeriesAttrTrendLine = (SeriesAttrTrendLine)getSeriesCollection().getSeriesCondition(new SeriesAttrTrendLine(), paramInt);
    TrendLine localTrendLine = null;
    if (localSeriesAttrTrendLine != null)
      localTrendLine = localSeriesAttrTrendLine.getLine();
    if (localTrendLine != null)
    {
      localTrendLine = (TrendLine)localTrendLine.clone();
      localTrendLine.fitting(paramArrayOfDouble1, paramArrayOfDouble2);
      localTrendLine.drawShape(new Rectangle2D.Double(0.0D, 0.0D, getBounds().getWidth(), getBounds().getHeight()));
      localDataSeries.setTrendLine(localTrendLine);
    }
  }

  public void setSeriesCollection(SeriesCollection paramSeriesCollection)
  {
    this.seriesCollection = paramSeriesCollection;
  }

  public SeriesCollection getSeriesCollection()
  {
    return this.seriesCollection;
  }

  public void setHotHyperLink(NameJavaScriptGroup paramNameJavaScriptGroup)
  {
    this.hotHyperLink = paramNameJavaScriptGroup;
  }

  public NameJavaScriptGroup getHotHyperLink()
  {
    return this.hotHyperLink;
  }

  public void setHotTooltip(String paramString)
  {
    this.hotTooltip = paramString;
  }

  public String getHotTooltip()
  {
    return this.hotTooltip;
  }

  public void setIsNullValueBreak(boolean paramBoolean)
  {
    this.isNullValueBreak = paramBoolean;
  }

  public boolean isNullValueBreak()
  {
    return this.isNullValueBreak;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("SeriesList"))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final PlotGlyph this$0;

          public void readXML()
          {
            if (paramXMLableReader.isChildNode())
            {
              String str = paramXMLableReader.getTagName();
              if (str.equals("DataSeries"))
                this.this$0.addSeries((DataSeries)paramXMLableReader.readXMLObject(new DataSeries()));
            }
          }
        });
      }
      else if (str1.equals("NewSeriesCollection"))
      {
        this.seriesCollection = ((SeriesCollection)paramXMLableReader.readXMLObject(new SeriesCollection()));
      }
      else if (("NameJavaScriptGroup".equals(str1)) || ("NameHyperlinks".equals(str1)) || ("HyperlinkMap".equals(str1)))
      {
        this.hotHyperLink = ((NameJavaScriptGroup)paramXMLableReader.readXMLObject(new NameJavaScriptGroup()));
      }
      else if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("hotTooltip")) != null)
          this.hotTooltip = str2;
        if ((str2 = paramXMLableReader.getAttr("isNullValueBreak")) != null)
          this.isNullValueBreak = Boolean.valueOf(str2).booleanValue();
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("PlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Attr").attr("hotTooltip", this.hotTooltip).attr("isNullValueBreak", this.isNullValueBreak).end();
    if ((this.seriesList != null) && (this.seriesList.size() > 0))
    {
      paramXMLPrintWriter.startTAG("SeriesList");
      for (int i = 0; i < this.seriesList.size(); ++i)
        ((DataSeries)this.seriesList.get(i)).writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    if (this.seriesCollection != null)
      this.seriesCollection.writeXML(paramXMLPrintWriter);
    if (this.hotHyperLink != null)
      this.hotHyperLink.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    int i;
    if (!(paramObject instanceof PlotGlyph))
      return false;
    PlotGlyph localPlotGlyph = (PlotGlyph)paramObject;
    if (!(super.equals(localPlotGlyph)))
      return false;
    if ((localPlotGlyph.seriesList != null) && (localPlotGlyph.seriesList.size() > 0))
      for (i = 0; i < localPlotGlyph.seriesList.size(); ++i)
        if (!(Equals.equals(localPlotGlyph.seriesList.get(i), this.seriesList.get(i))))
          return false;
    if (!(Equals.equals(localPlotGlyph.seriesCollection, this.seriesCollection)))
      return false;
    if (!(Equals.equals(localPlotGlyph.getHotHyperLink(), getHotHyperLink())))
      return false;
    if (!(Equals.equals(this.hotTooltip, localPlotGlyph.hotTooltip)))
      return false;
    return (this.isNullValueBreak == localPlotGlyph.isNullValueBreak);
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    int i;
    PlotGlyph localPlotGlyph = (PlotGlyph)super.clone();
    if (this.seriesCollection != null)
      localPlotGlyph.seriesCollection = ((SeriesCollection)this.seriesCollection.clone());
    if (this.seriesList != null)
    {
      localPlotGlyph.seriesList = new ArrayList();
      for (i = 0; i < this.seriesList.size(); ++i)
        localPlotGlyph.seriesList.add(((DataSeries)this.seriesList.get(i)).clone());
    }
    if (this.hotHyperLink != null)
      localPlotGlyph.hotHyperLink = ((NameJavaScriptGroup)this.hotHyperLink.clone());
    return localPlotGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    if (this.seriesCollection != null)
      localJSONObject.put("seriesCollection", this.seriesCollection.toJSONObject());
    if ((this.seriesList != null) && (this.seriesList.size() > 0))
    {
      Object[] arrayOfObject1 = this.seriesList.toArray();
      Object[] arrayOfObject2 = new Object[arrayOfObject1.length];
      for (int i = 0; i < arrayOfObject1.length; ++i)
        arrayOfObject2[i] = ((DataSeries)arrayOfObject1[i]).toJSONObject();
      localJSONObject.put("seriesList", arrayOfObject2);
    }
    if (this.hotHyperLink != null);
    localJSONObject.put("isNullValueBreak", this.isNullValueBreak);
    return localJSONObject;
  }

  public abstract String getPlotGlyphType();
}